package com.ly.honor.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.Clue;
import com.ly.honor.entity.dto.ClueCreateDTO;
import com.ly.honor.entity.dto.ClueEditDTO;
import com.ly.honor.entity.dto.ClueQueryDTO;
import com.ly.honor.entity.dto.NewsQueryDTO;
import com.ly.honor.entity.vo.ClueQueryVO;
import com.ly.honor.service.ClueService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * (Clue)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:59
 */
@RestController
@RequestMapping("clue")
@Validated
@Api(tags = "俱乐部管理")
public class ClueController {
    /**
     * 服务对象
     */
    @Resource
    private ClueService clueService;

    /**
     * 分页查询所有数据
     *
     * @param pageNum
     * @param pageSize
     * @param clueQueryDTO
     * @return
     */
    @ApiOperation("分页查询所有数据")
    @PostMapping("selectCluePage/{pageNum}/{pageSize}")
    public Result<Page<ClueQueryVO>> selectCluePage(@PathVariable("pageNum") long pageNum,
                                                    @PathVariable("pageSize") long pageSize,
                                                    @RequestBody(required = false) ClueQueryDTO clueQueryDTO) {
        Page<ClueQueryVO> clueQueryVOPage = clueService.selectCluePage(pageNum, pageSize, clueQueryDTO);
        return Result.ok(clueQueryVOPage);

    }

    @ApiOperation("查询所有俱乐部")
    @GetMapping("selectClueAll")
    public Result selectClueAll(){
        return Result.ok(clueService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

    @ApiOperation("通过id查询俱乐部")
    @GetMapping("getClueById/{id}")
    public Result<ClueQueryVO> getClueById(@PathVariable("id") long id) {
        ClueQueryVO clueQueryVO = clueService.getClueById(id);
        return Result.ok(clueQueryVO);
    }

    /**
     * 新增数据
     *
     * @param clue 实体对象
     * @return 新增结果
     */
    @ApiOperation("添加俱乐部")
    @PostMapping("insertClue")
    public Result insertClue(@RequestBody @Valid ClueCreateDTO clue) {
        clueService.insertClue(clue);
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param clueEditDTO 实体对象
     * @return 修改结果
     */
    @PostMapping("updateClue")
    @ApiOperation("修改俱乐部信息")
    public Result updateClue(@RequestBody ClueEditDTO clueEditDTO) {
        clueService.updateClue(clueEditDTO);
        return Result.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("deleteClueById/{id}")
    @ApiOperation("删除俱乐部")
    public Result delete(@PathVariable("id") Long id) {
        clueService.removeById(id);
        return Result.ok();
    }

    @DeleteMapping("removeBatch")
    @ApiOperation("批量删除俱乐部")
    public Result removeBatch(@RequestBody List<Long> idList) {
        clueService.removeByIds(idList);
        return Result.ok();
    }

    @PostMapping("upload")
    @ApiOperation("文件上传")
    public Result uploadFile(MultipartFile file){
        String url = clueService.upload(file);
        return Result.ok(url).message("上传文件成功");
    }

    @GetMapping("getLplClue")
    @ApiOperation("查看lpl赛区的战队")
    public Result getLplClue(){
        List<ClueQueryVO> clueQueryVOList = clueService.getLplClue();
        return Result.ok(clueQueryVOList);
    }

    @GetMapping("getLckClue")
    @ApiOperation("查看Lck赛区的战队")
    public Result getLckClue(){
        List<ClueQueryVO> clueQueryVOList = clueService.getLckClue();
        return Result.ok(clueQueryVOList);
    }

    @GetMapping("getOtherZoneClue")
    @ApiOperation("查看其他赛区的战队")
    public Result getOtherZoneClue(){
        List<ClueQueryVO> clueQueryVOList = clueService.getOtherZoneClue();
        return Result.ok(clueQueryVOList);
    }
}

